package cn.xfdzx.android.apps.shop.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.xfdzx.android.apps.shop.R;
import cn.xfdzx.android.apps.shop.bean.WithdrawalListBeen;
import cn.xfdzx.android.apps.shop.contract.ItemClickListener;

/**
 * @author gzk
 * @date 2020/4/13 0013
 * description：
 */
public class WithdrawalListAdapter extends RecyclerView.Adapter<WithdrawalListAdapter.MyViewHolder> {

    private ItemClickListener mItemClickListener;
    private List<WithdrawalListBeen.DataBean.OrderListBean> list;
    private Context mContext;
    private int type;



    public void setList(List<WithdrawalListBeen.DataBean.OrderListBean> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    public WithdrawalListAdapter(Context context, List<WithdrawalListBeen.DataBean.OrderListBean> list, int type, ItemClickListener listener) {
        this.list = list;
        this.mContext = context;
        this.type = type;
        this.mItemClickListener = listener;

    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_withdrawal_list, parent, false);
        MyViewHolder myHolder = new MyViewHolder(inflate);

        return myHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull final MyViewHolder holder, final int position) {
        holder.tvOrderPhone.setText(list.get(position).getOrder_sn());
        if (list.get(position).getOrder_status() == 0) {
            holder.tvState.setText("可提现订单");
            holder.tvState.setTextColor(mContext.getResources().getColor(R.color.color_333333));
            holder.tvOrderTotalPrice.setTextColor(mContext.getResources().getColor(R.color.color_333333));
            holder.ivShopSelect.setImageResource(R.drawable.d99999_oval);
            if (list.get(position).isIs_select()) {
                if (type == 0) {
                    holder.ivShopSelect.setImageResource(R.drawable.icon_select_orange);
                } else {
                    holder.ivShopSelect.setImageResource(R.drawable.icon_select_green);
                }
            } else {
                holder.ivShopSelect.setImageResource(R.drawable.d99999_oval);
            }

        }else  if (list.get(position).getOrder_status() == 1) {
            holder.tvState.setText("已完成");
            holder.tvState.setTextColor(mContext.getResources().getColor(R.color.color_999999));
            holder.tvOrderTotalPrice.setTextColor(mContext.getResources().getColor(R.color.color_999999));
            holder.ivShopSelect.setImageResource(R.drawable.d999999_round);
            if (list.get(position).isIs_select()){

            }else {

            }
        } else {
            holder.tvState.setText("银行清算中");
            holder.tvState.setTextColor(mContext.getResources().getColor(R.color.color_999999));
            holder.tvOrderTotalPrice.setTextColor(mContext.getResources().getColor(R.color.color_999999));
            holder.ivShopSelect.setImageResource(R.drawable.d999999_round);
            if (list.get(position).isIs_select()){

            }else {

            }
        }
        holder.tvTotalNum.setText("共" + list.get(position).getGoods_list().size() + "件");
        holder.tvOrderTime.setText(list.get(position).getAdd_time());
        holder.tvOrderTotalPrice.setText(list.get(position).getPay_price() + "元");
//        holder.ivShopSelect.setImageResource(R.drawable.icon_select_orange);

        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mContext);
        linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        holder.rvOrderGoods.setLayoutManager(linearLayoutManager);
        ItemWithdrawalImageAdapter itemAllOrderGoodsAdapter = new ItemWithdrawalImageAdapter(mContext, list.get(position).getGoods_list());
        holder.rvOrderGoods.setAdapter(itemAllOrderGoodsAdapter);



        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                list.get(position).setIs_select(!list.get(position).isIs_select());
                notifyDataSetChanged();
                mItemClickListener.onItemClick(position);
            }
        });
    }


    @Override
    public int getItemCount() {
        return list.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.tv_order_phone)
        TextView tvOrderPhone;
        @BindView(R.id.tv_state)
        TextView tvState;
        @BindView(R.id.rv_order_goods)
        RecyclerView rvOrderGoods;
        @BindView(R.id.tv_total_num)
        TextView tvTotalNum;
        @BindView(R.id.tv_order_time)
        TextView tvOrderTime;
        @BindView(R.id.tv_order_total_price)
        TextView tvOrderTotalPrice;
        @BindView(R.id.iv_shop_select)
        ImageView ivShopSelect;


        public MyViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);

        }
    }



}
